{extend name="admin@index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">添加商品</div>
    <div class="layui-card-body">
        <form class="layui-form" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">选择售货机</label>
                <div class="layui-input-inline">
                    <select name="machineid" lay-verify="required">
                        {volist name="machines" id="vo"}
                        <option value="{$vo['id']}" >{$vo['machinename']}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择商品</label>
                <div class="layui-input-inline">
                    <select name="goodsid" lay-verify="required">
                        {volist name="goods" id="vo"}
                        <option value="{$vo['id']}" >{$vo['goodsname']}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">总上货量</label>
                <div class="layui-input-inline">
                    <input type="text" style="width: 500px;" name="totalamount" lay-verify="required" autocomplete="off" placeholder="总上货量" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">当前货量</label>
                <div class="layui-input-inline">
                    <input type="text" style="width: 500px;" name="curamount" lay-verify="required" autocomplete="off" placeholder="当前货量" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所在货道</label>
                <div class="layui-input-inline">
                    <input type="text" style="width: 500px;" name="cargoway" lay-verify="required" autocomplete="off" placeholder="所在货道" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div>
                    <button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
                    <button class="layui-btn layui-btn-normal" type="button" onclick="javascript:history.back(-1);">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}

{block name="script"}
<script>
    //全局变量
    var GV = {
        'image_upload_url': '{$image_upload_url ? $image_upload_url : url("attachment/upload/upload", ["dir" => "images", "module" => request()->module()])}',
        'profile_upload_url': '{$profile_upload_url ? $profile_upload_url : url("machine/goods/profile")}',
        'image_url' : '{url("machine/goods/profile")}'
    };

    //上传图片
    if ($('.upload-img')[0]) {
        layui.use('upload', function(upload) {
            var avatarAdd = $('.avatar-add');
            upload.render({
                elem: '.upload-img',
                url: GV.image_upload_url,
                size: 1024,
                before: function() {
                    avatarAdd.find('.loading').show();
                },
                done: function(res) {
                    //console.log(res);
                    if (res.code == 0) {
                        document.getElementById("goodsimage").src = res.path;
                        document.getElementById("goodsimagestr").value = res.path;

                        console.log(res.path)

                        /*$.post(GV.profile_upload_url, {
                            avatar: res.path
                        }, function(res) {
                            //location.reload();
                        });*/
                    } else {
                        layer.msg(res.info, { icon: 5 });
                    }
                    avatarAdd.find('.loading').hide();
                },
                error: function() {
                    avatarAdd.find('.loading').hide();
                }
            });
        });
    }

    function openMsg(data) {
        var data = '<img id="pitureChange" style="width: 100%;height: 100%" src="' + data + '"  >'
        layer.msg(data, {
            time: 1000
        });
    }

    function openImage() {
        var imgstr = document.getElementById("goodsimage").src;

        openMsg(imgstr);
    }

</script>
{/block}